|
The top type in the type theory of mathematics, logic, and computer science, commonly abbreviated as top or by the ''down tack'' symbol (⊤), is the ''universal'' type, sometimes called the ''universal supertype'' as all other types in any given type system are subtypes of top. In most cases it is the type which contains every possible object in the type system of interest. It is in contrast with the bottom type, or the ''universal subtype'', which every other type is supertype of and in most cases it is the type that contains no members at all. ==Support in programming languages== Several typed programming languages provide explicit support for the top type. Note that in statically-typed languages, there are two different, often confused, concepts when discussing the top type. # A "universal base class" or other item at the top of a runtime ''class hierarchy'' (often relevant in object-oriented programming) or ''type hierarchy''; it is often possible to create objects with this actual (runtime) type, or it could be found when one examines the type hierarchy programmatically, in languages that support it # A (compile-time) ''static type'' in the code whose variables can be assigned any value (or a subset thereof, like any object pointer value), similar to dynamic typing The first concept often implies the second, i.e. if a universal base class exists, then a variable that can point to an object of this class can also point to an object of any class. However, several languages have types in the second regard above (e.g. void * in C++, id in Objective-C, interface The following object-oriented languages do not have a universal base class: * C++. The "pointer to void" type can accept any non-function pointer, even though the void type itself is not the universal type but the bottom type. * Objective-C. It is possible to create a new base class by not specifying a parent class for a class, although this is highly unusual. Object is conventionally used as the base class in the original Objective-C runtimes. In the OpenStep and Cocoa Objective-C libraries, NSObject is conventionally the universal base class. The top type for pointers to objects is id.* Swift. It is possible to create a new base class by not specifying a parent class for a class. The protocol Any can accept any type. * PHP. 抄文引用元・出典: フリー百科事典『 ウィキペディア(Wikipedia)』 ■ウィキペディアで「Top type」の詳細全文を読む スポンサード リンク
|